package com.example.demo.utils;

import com.example.demo.constant.HttpHeadConst;
import org.springframework.http.HttpEntity;
import org.springframework.http.HttpHeaders;

import java.util.Map;

/**
 * @author c10709
 * @Date 2018/10/20 14:28
 * @Description:
 */
public final class EntityWrapper<T> {

    private HttpHeaders headers;

    private EntityWrapper() {
        headers = new HttpHeaders();
        headers.add(HttpHeadConst.HTTP_HEAD_ACCEPT.toString(),HttpHeadConst.HTTP_MSG_TYPE.toString());
        headers.add(HttpHeadConst.HTTP_HEAD_CONTENT_TYPE.toString(), HttpHeadConst.HTTP_HEAD_CONTEXT_TYPE_JSON.toString());
    }

    public EntityWrapper addToken(String token) {
        headers.add(HttpHeadConst.HTTP_HEAD_X_AUTH_TOKEN.toString(), token);
        return this;
    }

    public EntityWrapper addCoreTarget(String coreTarget) {
        headers.add(HttpHeadConst.H3CLOUDOS_CORE_TARGET.toString(), coreTarget);
        return this;
    }

    public EntityWrapper addSubjectToken(String token) {
        headers.add(HttpHeadConst.HTTP_HEAD_X_SUBJECT_TOKEN.toString(), token);
        return this;
    }

    public EntityWrapper addCmpCloudId(String cloudId) {
        headers.add(HttpHeadConst.HEADER_CMP_CLOUD_ID.toString(), cloudId);
        return this;
    }

    public EntityWrapper addHeaderMap(Map<String,String> headerMap) {
        headers.setAll(headerMap);
        return this;
    }



    public HttpHeaders headers() {
        return headers;
    }

    public static EntityWrapper build() {
        return new EntityWrapper();
    }

    public HttpEntity<T> entity(T body) {
        return new HttpEntity<>(body,headers);
    }

    public HttpEntity entity() {
        return new HttpEntity(headers);
    }

}
